package cn.calm.commons.interceptor;

import org.apache.log4j.Logger;

import cn.calm.commons.action.BaseAction;
import cn.calm.commons.exception.DeskException;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class DeskExceptionInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final Logger logger = Logger.getLogger(DeskExceptionInterceptor.class);
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		BaseAction<?> action=(BaseAction<?>) invocation.getAction();
		try {
			String result= invocation.invoke();
			return result;
		} catch (DeskException e) {
			action.addActionError(e.getMessageInfo());
			return "input";
		}catch (Exception e) {
			logger.error(e.getMessage(),e);
			return "input";
		}
	}
}
